package com.framework.loippi.utils;


import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;

/**
 * @ClassName TimeByGapToList
 * @Description 根据间隔将时间分隔成数组
 * @Author fsociety
 * @Date 27/12/2019 下午3:35
 * @Version 1.0
 */
public class TimeByGapToList {
    /**
     * 获取固定间隔时刻集合
     * @param start 开始时间
     * @param end 结束时间
     * @param interval 时间间隔(单位：分钟)
     * @return
     */
    public static List<String> getIntervalTimeList(String start,String end,int interval){
        Date startDate = DateTimeUtils.convertString2Date("HH:mm:ss",start);
        Date endDate = DateTimeUtils.convertString2Date("HH:mm:ss",end);
        List<String> list = new ArrayList<>();
        while(startDate.getTime()<=endDate.getTime()){
            list.add("\"" + DateTimeUtils.convertDate2String("HH:mm:ss",startDate) + "\"");
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(startDate);
            calendar.add(Calendar.MINUTE,interval);
            if(calendar.getTime().getTime()>endDate.getTime()){
                if(!startDate.equals(endDate)){
                    list.add("\"" + DateTimeUtils.convertDate2String("HH:mm:ss",endDate) + "\"");
                }
                startDate = calendar.getTime();
            }else{
                startDate = calendar.getTime();
            }

        }
        return list;
    }

}
